﻿@model  IQueryable<YTCMS.Domain.Entities.viewcompany>
@using YTCMS.Core
<table class="table table-striped table-bordered bootstrap-datatable datatable table-hover">
    <thead>
        <tr>
            <th>机构名称</th>
            <th>机构代码</th>
            <th>机构法人</th>
            <th>机构联系人</th>
            <th>机构联系电话</th>
            <th>状态</th>
            <th>金额(人民币)</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @{
            if (Model.Any())
            { 
                foreach (var item in Model)
                {
                    <tr>
                        <td>@item.UserName</td>
                        <td>@item.Code</td>
                        <td>@item.Legal</td>
                        <td>@item.Contacts</td>
                        <td>@item.Mobile</td>
                        <td>
                            @Html.Raw(Enum.GetName(typeof(YTCMS.Core.CommonState), item.State).AdminStateExtend())
                        </td>
                        <td>@item.Money ￥</td>
                        <td>@item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")</td>
                        <td>
                            @*<a class="btn btn-success" href="/company/Details?id=@item.Id">
                                <i class="fa fa-search-plus ">详情</i>
                            </a>*@

                            <a class="btn btn-info" href="/company/edit?id=@item.Id">
                                <i class="fa fa-edit ">修改</i>
                            </a>
                            <a class="btn btn-primary defaultDOMWindow" value="@item.Id" href="javascript:void(0)">
                                <i class="fa fa-asterisk">修改密码</i>
                            </a>
                            <a class="btn btn-warning" href="javascript:void(0)" value="@item.Id" name="recharge">
                                <i class="fa fa-plus-square ">手动充值</i>
                            </a>

                            <a class="btn btn-danger" onclick="YTDelete('/company/Delete', {id:@item.Id})">
                                <i class="fa fa-trash-o ">删除</i>

                            </a>
                        </td>
                    </tr>
                }
            }
        }
        
    </tbody>
</table>
@Html.Hidden("hidId")
<div id="inlineContent" style=" display:none;">
    <p>修改密码：</p>
    <p><input type="text" id="newpwd" /> <input type="button" class="btn btn-sm btn-primary " value="修改" id="btn_updatepwd" /></p>
</div>

<div class="row" id="rechargeContent" style="display:none">
    <div class="col-xs-6">
        <p>充值金额：</p>
        <p><input type="text" id="txt_money" /> <input type="button" class="btn btn-sm btn-primary " value="充值/提现" id="btnrecharge" /></p>
    </div>
</div>

<script>
    $(function () {
        $('.defaultDOMWindow').click(function () {
            var that = $(this);
            that.openDOMWindow({
                loader: 1,
                loaderHeight: 19,
                loaderWidth: 20,
                windowSourceID: '#inlineContent',
                height: 100,
                width: 700,
                callback: function (r) {
                    var id = that.attr("value");
                    $("#hidId").val(id)
                }
            })
        })
        $("a[name='recharge']").click(function () {
            var that = $(this);
            that.openDOMWindow({
                loader: 1,
                loaderHeight: 19,
                loaderWidth: 20,
                windowSourceID: '#rechargeContent',
                height: 100,
                width: 600,
                callback: function (r) {
                    var id = that.attr("value");
                    $("#hidId").val(id)
                }
            })
        });
        $("#btn_updatepwd").click(function () {
            var newpwd = $("#newpwd").val();
            var uid = $("#hidId").val();
            $.post("/Users/EditPwd", { "uid": uid, "pwd": newpwd }, function (result) {
                if (result.d) {
                    jAlert("修改密码成功", "提示", function () {
                        window.location.href = window.location.href;
                    })
                }
                else {
                    jAlert(result.msg, "提示")
                }
            })
        });

        $("#btnrecharge").click(function () {
            var money = $("#txt_money").val();
            var uid = $("#hidId").val();
            $.post("/company/Recharge", { "uid": uid, "money": money}, function (result) {
                if (result.d) {
                    jAlert("操作成功", "提示", function () {
                        window.location.href = window.location.href;
                    })
                }
                else {
                    jAlert(result.msg, "提示")
                }
            })
        });
    })

</script>